package com.wb3.meta.config.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wb3.meta.common.utils.ConcurrentHttpClient;
import com.wb3.meta.common.utils.HttpUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Configuration
public class BaichuanUtils {

    private static final String MODEL_TURBO = "Baichuan-NPC-Turbo";
    private static final String MODEL_LITE = "Baichuan-NPC-Lite";
    @Value("${baichuan.key}")
    private String key;

    public Map<String,String> getChatInfo(Integer characterId, List<BaichuanUtils.Message> historyChatList) {
        String msgs = JSONArray.toJSONString(historyChatList);
        String url = "https://api.baichuan-ai.com/v1/chat/completions";
        String data = "{\"model\":\"" + MODEL_LITE + "\"" +
                ",\"character_profile\":{\"character_id\":\"" + characterId + "\"}" +
                ",\"messages\":"+msgs+"}";
        log.info("请求百川的数据：{}",data);
        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "Bearer " + key);


        return ConcurrentHttpClient.doPostJson(url, headers, data);
    }
    @AllArgsConstructor
    @Data
    public static class Message{
        private String role;
        private String content;
    }
}
